import 'package:flutter/material.dart';
import 'package:flutter_boost/flutter_boost.dart';

class SecondPageWidget extends StatefulWidget {
  final Map params;
  SecondPageWidget(this.params);

  @override
  _SecondPageWidgetState createState() => _SecondPageWidgetState(params);
}

class _SecondPageWidgetState extends State<SecondPageWidget> {
  final Map params;
  _SecondPageWidgetState(this.params);

  String value = '';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("secondPage"),
        ),
        body: Column(
          children: <Widget>[
            Text("参数是：$params"),
            ElevatedButton(
              onPressed: () {
                // 关闭dart页面
                BoostNavigator.instance.pop();
              },
              child: Text('Go back!'),
            ),
            ElevatedButton(
              onPressed: () {
                BoostNavigator.instance.pop();
                Future.delayed(Duration(milliseconds: 500), () {
                  BoostNavigator.instance.push("firstPage",
                      arguments: {"key": "second跳过来的", "isAnimated": "1"},
                      withContainer: true);
                });
              },
              child: Text('跳转firstPage传递参数'),
            ),
            ElevatedButton(
                child: Text('Flutter call Native'),
                onPressed: _secondflutterCallNative),
            Text(value.length > 0 ? "收到消息：$value" : '')
          ],
        ));
  }

  Future<Null> _secondflutterCallNative() async {
    BoostChannel.instance.sendEventToNative("flutter_to_native", {"key":"second传参过来"});
  }
}
